//@author A0103459H

#include "interpreter.h"


#define TASK_DATA_VECTOR_SIZE 	7
#define TASK_NAME 				0
#define START_TIME 				1
#define END_TIME 				2
#define VENUE 					3
#define STATUS 					4
#define NEW_TASK_NAME 			5
#define ON_DATE 				6

#define FIRST_WORD 				0
#define MAX_BUFFER 				80

using namespace std;

const string Interpreter::ZERO_STRING = "0";

const string Interpreter::IDENTIFIER_VENUE 				= "at";
const string Interpreter::IDENTIFIER_START_END_DATE 	= "on";
const string Interpreter::IDENTIFIER_START_TIME 		= "from";
const string Interpreter::IDENTIFIER_END_TIME_TO 		= "to";
const string Interpreter::IDENTIFIER_END_TIME_BY 		= "by";
const string Interpreter::IDENTIFIER_RENAME 			= ">";

const string Interpreter::STD_DATE_FORMAT			 = "%H %M %d %m %Y";
const string Interpreter::ZERO_ZERO					 = "00";
const string Interpreter::EMPTY_STRING				 = "";
const string Interpreter::YEAR_FIRST_TWO_DIGITS_STRING	= "20";


const string Interpreter::NOW_KEYWORD				 = "now";
const string Interpreter::TODAY_KEY_WORD             = "today";
const string Interpreter::TODAY_KEY_WORD_SHORTCUT    = "tdy";
const string Interpreter::TOMORROW_KEY_WORD          = "tomorrow";
const string Interpreter::TOMORROW_KEY_WORD_SHORTCUT = "tmr";
const string Interpreter::MON_KEY_WORD               = "mon";
const string Interpreter::MON_FULL_KEY_WORD          = "monday";
const string Interpreter::TUE_KEY_WORD               = "tue";
const string Interpreter::TUE_FULL_KEY_WORD          = "tuesday";
const string Interpreter::WED_KEY_WORD               = "wed";
const string Interpreter::WED_FULL_KEY_WORD          = "wednesday";
const string Interpreter::THU_KEY_WORD               = "thu";
const string Interpreter::THU_FULL_KEY_WORD          = "thursday";
const string Interpreter::FRI_KEY_WORD               = "fri";
const string Interpreter::FRI_FULL_KEY_WORD          = "friday";
const string Interpreter::SAT_KEY_WORD               = "sat";
const string Interpreter::SAT_FULL_KEY_WORD          = "saturday";
const string Interpreter::SUN_KEY_WORD               = "sun";
const string Interpreter::SUN_FULL_KEY_WORD          = "sunday";
const string Interpreter::AM_KEYWORD				 = "am";
const string Interpreter::PM_KEYWORD				 = "pm";

const regex Interpreter::dateTimeFormatInCtime	("(([a-z]{3})( )([a-z]{3})( )[0-3][0-9]( )[0-2][0-9](:)[0-5][0-9](:)[0-5][0-9]( )(20)[0-9][0-9])");
const regex Interpreter::dateFormat1			("(^| )(([0-3]?)[0-9](/|-)((0?[1-9])|1[0-2])(-|/)((20)?)[0-9][0-9])( |$)");
const regex Interpreter::dateFormat2			("(^| )(([0-3]?)[0-9](/|-)((0?[1-9])|1[0-2]))( |$)");
const regex Interpreter::dateFormat3			("(^| )([a-z]{3})( |$)");
const regex Interpreter::dateFormat4			("(^| )(([a-z]{2,6})(day))( |$)");

const regex Interpreter::timeFormat1			("(^| )([0-2][0-9](:?)[0-5][0-9])(hrs| |$)");
const regex Interpreter::timeFormat2			("(^| )(((0?[0-9])|1[0-2])(:?)([0-5]?)([0-9]?)(a|p)(m))( |$)");

const char Interpreter::SLASH                        = '/';
const char Interpreter::DOT                          = '.';
const char Interpreter::SPACE                        = ' ';
const char Interpreter::DASH                         = '-';
const char Interpreter::COLON                        = ':';

const int Interpreter::ZERO_INT							= 0;
const int Interpreter::REGEX_MATCH_NUM					= 2;
const int Interpreter::MAX_NUM_OF_DIGITS_IN_DAY_MONTH 	= 2;
const int Interpreter::INTERNAL_ERROR_SIGNAL			= -1;		//to be changed if there is a possibility of -1 being involved in the program. 
const int Interpreter::NUM_DAYS_IN_A_WEEK				= 7;

//-------------------------------------------------------------------
//The only function that logic calls

vector<string> Interpreter::interpret(string userInput, string *command, int* returnFlag) {

	splitWords(userInput);	//Splits the string into individual words and pushes the words in a vector: tempWords

	*command = extractFirstWordInLowerCase();
	assignTempWordsToTaskData();
	*returnFlag = updateStartEndTime();

	userInput.clear();
	return taskData; 
}



//--------------------------------------------------------------------
//First Level Supporting functions

void Interpreter::splitWords(string userInput) {

	istringstream toInterpret(userInput);   
	   string word;
	   while (toInterpret >> word) {
		   tempWords.push_back(word);	
	   }   	   
}

string Interpreter::extractFirstWordInLowerCase() {
	return toLowerString(tempWords[FIRST_WORD]);
}

void Interpreter::assignTempWordsToTaskData() {
	//This functions assigns the words to the respective task detail. Until a keyword is discovered the words from
	//tempWords is continued added to the attribute specific to the last specified keyword. 
	//If not keyword is discovered everything goes into the task name. 

	int taskDetailIndex = TASK_NAME;

	initializeTaskDataWithEmptyStrings();

	assert (tempWords.size() > 0);

	for (int i = 1; i < Interpreter::tempWords.size(); i++) {
		// i starts at 1, since we ignore the first word (assigned to command).
		if (Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_VENUE) {
			taskDetailIndex = VENUE;
		}
		else if (Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_START_TIME) {
			taskDetailIndex = START_TIME;
		}
		else if ((Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_END_TIME_TO) || (Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_END_TIME_BY)) {
			taskDetailIndex = END_TIME;
		}
		else if (Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_START_END_DATE) {
			taskDetailIndex = ON_DATE;
		} else if (Interpreter::toLowerString(tempWords[i]) == IDENTIFIER_RENAME) {
			taskDetailIndex = NEW_TASK_NAME;
		}
		
		else { 
		Interpreter::taskData[taskDetailIndex] += Interpreter::tempWords[i];
		Interpreter::taskData[taskDetailIndex] += SPACE;
		}
	}

	removeEndWhiteSpaces(taskData);

	return;
}

int Interpreter::updateStartEndTime() {

	bool isOn = (taskData[ON_DATE] != EMPTY_STRING);
	bool isFrom = (taskData[START_TIME] != EMPTY_STRING);
	bool isTo = (taskData[END_TIME] != EMPTY_STRING);

	if (isFrom && !isTo) {
		return ERROR_INTERPRETER_START_TIME_BUT_NO_END_TIME;
	}
	
	if (isOn) {
		assignOnToFromTo();
	}

	time_t startTimeInTime_T = getCurrentTimeInTime_T();
	time_t endTimeInTime_T = getCurrentTimeInTime_T();

	bool isStartTimeDeclared = (isFrom || isOn);
	bool isEndTimeDeclared = (isTo || isOn);

	int returnFlag = SUCCESS_INTERPRETER;	

	if  (taskData[START_TIME] == NOW_KEYWORD) {
		time_t curTime = getCurrentTimeInTime_T();
		taskData[START_TIME] = ctime(&curTime);
	}

// Deals with Start Time. 
	if (isStartTimeDeclared) {
		returnFlag = updateTimeToCtimeFormat(taskData[START_TIME], startTimeInTime_T);
		if (returnFlag != SUCCESS_INTERPRETER) {
			return returnFlag;
		}
	}	

// Deals with End Time.
	if (isEndTimeDeclared) {
		returnFlag = updateTimeToCtimeFormat(taskData[END_TIME], endTimeInTime_T);
		if (returnFlag != SUCCESS_INTERPRETER) {
			return returnFlag;
		}
	}

	if (isStartTimeDeclared && isEndTimeDeclared) {
		if (!isStartBeforeEnd (startTimeInTime_T, endTimeInTime_T)) {
			returnFlag = ERROR_ENDTIME_BEFORE_STARTTIME;
			return returnFlag;
		}
	}
	return returnFlag;
}


//--------------------------------------------------------------------
//Second Level Support Functions


int Interpreter::updateTimeToCtimeFormat(string &timeString, time_t &timeInTime_T) {
	
	timeInTime_T = getCurrentTimeInTime_T();

	int returnFlag = SUCCESS_INTERPRETER;	

	if (timeString != EMPTY_STRING && !isCTimeFormat(timeString)) {
			timeInTime_T = interpretDateTime(timeString, &returnFlag);
			if (returnFlag != SUCCESS_INTERPRETER) {
				return returnFlag;
			}
			timeString = ctime(&timeInTime_T);
			timeString = timeString.substr(ZERO_INT,timeString.size()-1);		//eliminate the last '\n' character.
	}
	return returnFlag;
}

bool Interpreter::isCTimeFormat (string timeInput) {
	timeInput = toLowerString(timeInput);									
	smatch resultTime;

	return (regex_search(timeInput, resultTime, dateTimeFormatInCtime));
}

void Interpreter::assignOnToFromTo() {
	assert(!taskData[ON_DATE].empty());

	taskData[START_TIME] += taskData[ON_DATE];
	taskData[END_TIME] += taskData[ON_DATE];
	taskData[ON_DATE] = EMPTY_STRING;
}

time_t Interpreter::interpretDateTime (string timeInput, int* returnFlag) {
	time_t rawtime, outputTime;
	struct tm* timeinfo;
	int year, month ,day, hour, minute;
	time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	char buffer[MAX_BUFFER]; 

	timeInput = createStdTimeStringForInput(timeInput, returnFlag);

	if (*returnFlag == ERROR_INTERPRETER_DATETIME_FORMAT) {
		return rawtime;
	}
	
	istringstream timeInfoStream (timeInput);

	timeinfo->tm_sec = ZERO_INT;

	if (timeInfoStream >> hour) {
		timeinfo->tm_hour = hour;
	} 
	if (timeInfoStream >> minute) {
		timeinfo->tm_min = minute;
	} 

	if (timeInfoStream >> day) {
		timeinfo->tm_mday = day;
	} 

	if (timeInfoStream >> month) {
		timeinfo->tm_mon = month - 1;
	} 

	if (timeInfoStream >> year) {
		timeinfo->tm_year = year - 1900;
	} 
			
	outputTime = mktime(timeinfo);
	strftime (buffer, MAX_BUFFER, STD_DATE_FORMAT.c_str(), timeinfo);	//fills the buffer in the form "HH MM DD MM YYYY"
	
	if (isValidDateTime((string)buffer, timeInput)) { 
		*returnFlag = SUCCESS_INTERPRETER;
	} else {
		*returnFlag = ERROR_INTERPRETER_DATETIME_INVALID;
	}
	return outputTime;
}

string Interpreter::createStdTimeStringForInput(string timeInput, int* returnFlag) {

	timeInput = toLowerString(timeInput);
	string inputDateString;
	string inputTimeString;

	string timeOutput;
	string dateOutput;

	bool isValidTimeFormat = false;
	bool isValidDateFormat = false;
	bool isValidDateTimeFormat = false;

	
	int numberOfWords = wordCounter(timeInput);

	if (numberOfWords > 2) {
		//Number of words expected from user for time is a max of 2; 1 for time, 1 for date.
		*returnFlag = ERROR_INTERPRETER_PARAMETER_OVERLOAD_TIME;
		return EMPTY_STRING;
	}

	replace( timeInput.begin(), timeInput.end(), DOT, SLASH);		//the regex search does not accept DOTs
	
	smatch resultTime;
	smatch resultDate;


	if (regex_search(timeInput, resultTime, timeFormat1)) {
		inputTimeString = resultTime.str(REGEX_MATCH_NUM);
		inputTimeString = removeAllSpacesFromString(inputTimeString); 
		if (inputTimeString.at(2) == ':') {inputTimeString.erase(2,1);}
		timeOutput = inputTimeString.substr(0,MAX_NUM_OF_DIGITS_IN_DAY_MONTH) + " " + inputTimeString.substr(2,MAX_NUM_OF_DIGITS_IN_DAY_MONTH);
		if (timeOutput != EMPTY_STRING) {isValidTimeFormat = true;}
	} else if (regex_search(timeInput, resultTime, timeFormat2)) {
		inputTimeString = (resultTime.str(REGEX_MATCH_NUM));
		inputTimeString = removeAllSpacesFromString(inputTimeString);
		timeOutput = convert12hrTo24hr(inputTimeString); //convert12hrto24hr(inputTimeString);
		if (timeOutput != EMPTY_STRING) {isValidTimeFormat = true;}
	} else {
		timeOutput = EMPTY_STRING;
		isValidTimeFormat = false;
	}


	if (regex_search(timeInput, resultDate, dateFormat1)) {
		inputDateString = resultDate.str(REGEX_MATCH_NUM);
		inputDateString = removeAllSpacesFromString(inputDateString);
		dateOutput = convertStdDate(inputDateString);		
		if (dateOutput != EMPTY_STRING) {isValidDateFormat = true;}
	} else if (regex_search(timeInput, resultDate, dateFormat2)) {
		inputDateString = resultDate.str(REGEX_MATCH_NUM);
		inputDateString = removeAllSpacesFromString(inputDateString);
		dateOutput = convertStdDate(inputDateString);	
		if (dateOutput != EMPTY_STRING) {isValidDateFormat = true;}
	} else if (regex_search(timeInput, resultDate, dateFormat3)) {
		inputDateString = resultDate.str(REGEX_MATCH_NUM);
		inputDateString = removeAllSpacesFromString(inputDateString);
		dateOutput = convertStdDateFromDayName(inputDateString);
		if (dateOutput != EMPTY_STRING) {isValidDateFormat = true;}	
	} else if (regex_search(timeInput, resultDate, dateFormat4)) {
		inputDateString = resultDate.str(REGEX_MATCH_NUM);
		inputDateString = removeAllSpacesFromString(inputDateString);
		dateOutput = convertStdDateFromDayName(inputDateString);
		if (dateOutput != EMPTY_STRING) {isValidDateFormat = true;}
	} else {
		dateOutput = EMPTY_STRING;
		isValidDateFormat = false;
	}

	int parametersValid = isValidDateFormat + isValidTimeFormat;

	if (parametersValid != numberOfWords) {
		*returnFlag = ERROR_INTERPRETER_DATETIME_FORMAT;
		return EMPTY_STRING;
	}

	if (isValidDateFormat && isValidTimeFormat) {
		return timeOutput + SPACE + dateOutput;
	} else if (isValidDateFormat && !isValidTimeFormat) {
		return (ZERO_ZERO + SPACE + ZERO_ZERO + SPACE + dateOutput);
	} else if (!isValidDateFormat && isValidTimeFormat) {
		return timeOutput;
	} else if (!isValidDateFormat && !isValidTimeFormat) {
		*returnFlag = ERROR_INTERPRETER_DATETIME_FORMAT;
		return EMPTY_STRING;
	} else {
		*returnFlag = ERROR_INTERPRETER_DATETIME_FORMAT;
		return EMPTY_STRING;
	}

}

bool Interpreter::isStartBeforeEnd(time_t startTime, time_t endTime) {
	double timeDifference = difftime (endTime, startTime);

	if (timeDifference < ZERO_INT) {
		return false;
	} else {
		return true;
	}
}

//----------------------------------------------------------------------
//Third level Support Functions


string Interpreter::convert12hrTo24hr (string input12hr) {
	string output24hr;
	bool isAM = (input12hr.substr(input12hr.length()-AM_KEYWORD.size()) == AM_KEYWORD);
	bool isPM = (input12hr.substr(input12hr.length()-PM_KEYWORD.size()) == PM_KEYWORD);

	input12hr.pop_back();
	input12hr.pop_back();

	int sizeInputString = input12hr.size();

	if (isAM) {
		if (sizeInputString == 1) {
			// handles single digit time : 1-9
			output24hr = ZERO_STRING + input12hr + SPACE + ZERO_STRING + ZERO_STRING;
		} else if (sizeInputString == 2) {
			//handles double digit time : 10-12
			if (input12hr == "12") {
			//handles 12am as 0000hrs. 
				output24hr = ZERO_ZERO + SPACE + ZERO_ZERO;
			} else {
				output24hr = input12hr + SPACE + ZERO_ZERO;
			}
		} else if (sizeInputString == 5) {
			//handles for the format HH:MM (5 char in length)
			output24hr = input12hr.replace(input12hr.find(COLON),1, " ");		//replace COLON with a SPACE
			if (output24hr.substr(0,2) == "12") {
			//handles 12:MMam as 00MMhrs
				output24hr = ZERO_ZERO + output24hr.substr(ZERO_ZERO.size());	
			}
		} else if (sizeInputString == 4) {
			//handles the case where the time is of the format H:MMam & HHMMam
			input12hr = ZERO_STRING + input12hr;
			size_t colonPosition = input12hr.find(COLON);
			if (colonPosition != string::npos) {
				output24hr = input12hr.replace(input12hr.find(COLON),1, " ");		//replace COLON with a SPACE
			} else {
				return EMPTY_STRING;
			}
		} else {
			output24hr = EMPTY_STRING;											//this is an impossible case.
		}

	} else if (isPM) {
		if (sizeInputString <= 2) {
			istringstream inputStream (input12hr);
			int hour; 
		
			inputStream >> hour;
		
			if (hour != 12) {
				hour = hour + 12;
			}
			ostringstream outputStream;
			outputStream << hour << SPACE <<ZERO_ZERO;
			output24hr = outputStream.str();
		} else if (sizeInputString == 5 || sizeInputString == 4) {
			size_t colonPosition = input12hr.find(COLON);
			if (colonPosition != string::npos) {
				output24hr = input12hr.replace(input12hr.find(COLON),1, " ");		//replace COLON with a SPACE
			} else {
				return EMPTY_STRING;
			}
			istringstream inputStream (input12hr);
			int hour; 
			string minute;
		
			inputStream >> hour;
			inputStream >> minute;
		
			if (hour != 12) {
				hour = hour + 12;
			}

			ostringstream outputStream;
			outputStream << hour << SPACE << minute;
			output24hr = outputStream.str();
		}

	} else {
		output24hr = EMPTY_STRING;											//impossible case.
	}

	return output24hr;
}

string Interpreter::convertStdDate (string inputDate) {
	string day;
	string month;
	string year;
	string outputStdDate;

	string::iterator it;
	for (it = inputDate.begin(); it < inputDate.end(); it++) {
		if (*it == DOT||*it ==SLASH||*it == DASH) {
			*it = SPACE;
		}
	}

	istringstream inputStream(inputDate);

	inputStream >> day;
	inputStream >> month;

	if (inputStream >> year) {
		if (year.size() == 2) {
			year = YEAR_FIRST_TWO_DIGITS_STRING + year;
		}
	} else {
		year = EMPTY_STRING;
	}

	outputStdDate = day + SPACE + month + SPACE + year;
	return outputStdDate;
}

string Interpreter::convertStdDateFromDayName (string inputDayName) {
	time_t rawtime = getCurrentTimeInTime_T();
	struct tm * timeinfo;
	int day, dayNameIndex;
	timeinfo = localtime ( &rawtime );

	day = timeinfo->tm_mday;

	dayNameIndex = timeinfo->tm_wday;
	int numberOfDaysFromToday = calculateNumberOfDaysFromToday(inputDayName, dayNameIndex);

	day = day + numberOfDaysFromToday;
	timeinfo->tm_mday = day;

	ostringstream outDate; 
	if (numberOfDaysFromToday == INTERNAL_ERROR_SIGNAL) {
		return EMPTY_STRING;
	} else {
		outDate<< timeinfo->tm_mday << SPACE << (timeinfo->tm_mon + 1) << SPACE << (timeinfo->tm_year+1900);	
		//tm_mon+1 helps to reconcile month index which runs from 0,11
	}
	return outDate.str();
}

bool Interpreter::isValidDateTime (string interpretedTime, string userInputInStdStringFormat) {
	//This functions validates the date and takes care of the number of days, leap year etc.
	//The method used is comparison of the date, day, month with an equivalent date generated using mktime.

	istringstream userInput(userInputInStdStringFormat);
	istringstream interpretedInput(interpretedTime);

	int fromUserAttribute, interpretedAttribute;
	
	while (userInput >> fromUserAttribute) {
		interpretedInput >> interpretedAttribute;
		if (fromUserAttribute != interpretedAttribute) {
			return false;
		}
	}
	return true;
}



//-----------------------------------------------------------------------
//Fourth level Support Functions

time_t Interpreter::getCurrentTimeInTime_T() {
	time_t rawtime;
	time ( &rawtime );

	return rawtime;
}

int Interpreter::calculateNumberOfDaysFromToday(string inputDayName, int todayDayNameIndex) {
	if ((inputDayName == TODAY_KEY_WORD)||(inputDayName == TODAY_KEY_WORD_SHORTCUT)) {
		return 0;
	} else if ((inputDayName == TOMORROW_KEY_WORD)||(inputDayName == TOMORROW_KEY_WORD_SHORTCUT)) {
		return 1;
	} else {
		int dayNameIndexFromInput = mapDayOfWeekToInt(inputDayName);

		int count = ((NUM_DAYS_IN_A_WEEK + dayNameIndexFromInput - todayDayNameIndex)% NUM_DAYS_IN_A_WEEK);		

		if (dayNameIndexFromInput == INTERNAL_ERROR_SIGNAL) {
			return dayNameIndexFromInput;
		} else {
			return count;	
		}
	}
}

int Interpreter::mapDayOfWeekToInt(const string &str1){
	if (str1==SUN_KEY_WORD || str1==SUN_FULL_KEY_WORD){
		return INT_SUNDAY;
	}else if(str1==MON_KEY_WORD || str1==MON_FULL_KEY_WORD){
		return INT_MONDAY;
	}else if(str1==TUE_KEY_WORD || str1==TUE_FULL_KEY_WORD){
		return INT_TUESDAY;
	}else if(str1==WED_KEY_WORD || str1==WED_FULL_KEY_WORD){
		return INT_WEDNESDAY;
	}else if(str1==THU_KEY_WORD || str1==THU_FULL_KEY_WORD){
		return INT_THURSDAY;
	}else if(str1==FRI_KEY_WORD || str1==FRI_FULL_KEY_WORD){
		return INT_FRIDAY;
	}else if(str1==SAT_KEY_WORD || str1==SAT_FULL_KEY_WORD){
		return INT_SATURDAY;
	}else{
		return INTERNAL_ERROR_SIGNAL;
	}
}

//--------------------------------------------------------------------
// SUPPORT FUNCTIONS

string Interpreter::toLowerString (string input) {
	transform(input.begin(), input.end(), input.begin(), ::tolower);
	return input;
}

void Interpreter::removeEndWhiteSpaces(vector<string> &input) {
	for (int i = 0; i < input.size(); i++) {
		while ((input[i] != EMPTY_STRING) && (input[i].back() == SPACE)) {
			input[i].pop_back();
		}
	}
}

string Interpreter::removeAllSpacesFromString(string input) {
  input.erase(remove_if(input.begin(), input.end(), isspace),input.end());
  return input;
}

void Interpreter::initializeTaskDataWithEmptyStrings() {
	for (int j = 0; j < TASK_DATA_VECTOR_SIZE; j++)
	{
		taskData.push_back(EMPTY_STRING);
	}
}

int Interpreter::wordCounter(string input) {
	int nSpaces = 0;

	for (int i = 0; i < input.size(); ++i) {
		if (input[i] == SPACE) {
			++nSpaces;
		}
	}
	return ++nSpaces;
}

string Interpreter::addZeroFromFront(string inString){
	if (inString.size()==MAX_NUM_OF_DIGITS_IN_DAY_MONTH-1){
		return ZERO_STRING+inString;
	}else{
		return inString;
	}
}

//--------------------------------------------------------------------



//Deleted code

/*if (isCTimeFormat(startTime)) {
			taskData[START_TIME] = startTime;
		} else {
			startTimeInTime_T = interpretDateTime(startTime, &returnFlag);
			if (returnFlag != SUCCESS_INTERPRETER) {
				return returnFlag;
			}
			startTime = ctime(&startTimeInTime_T);
			taskData[START_TIME] = startTime.substr(0,24);
		}*/

/*if (isCTimeFormat(endTime)) {
			taskData[END_TIME] = endTime;
		} else {
			endTimeInTime_T = interpretDateTime(endTime, &returnFlag);
			if (returnFlag != SUCCESS_INTERPRETER) {
				return returnFlag;
			}
			endTime = ctime(&endTimeInTime_T);
			taskData[END_TIME] = endTime.substr(0,24);		
		}*/